//
//  MovieDetailControllerViewController.m
//  UI-豆瓣项目APP
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 孙鹏. All rights reserved.
//

#import "MovieDetailControllerViewController.h"
#import "DateBaseSingleton.h"
#import "MovieDetailTableViewCell.h"
#import "MovieDetalViewController.h"
@interface MovieDetailControllerViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation MovieDetailControllerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.userMovieDetailVC = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.userMovieDetailVC.delegate = self;
    self.userMovieDetailVC.dataSource = self;
    [self.view addSubview:self.userMovieDetailVC];

    
    [self.userMovieDetailVC registerClass:[MovieDetailTableViewCell class] forCellReuseIdentifier:@"cell"];

    
    
    self.navigationItem.title = @"我的电影";
    
    // Do any additional setup after loading the view.
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 60;
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *userName = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
    
    self.rowArray = [NSMutableArray array];
    self.rowArray = [[DateBaseSingleton shareDateBase]selectMovieUserName:userName];
    
    
    
    
//    array = [[DateBaseSingleton shareDateBase]selectMovieDetail];
//    self.rowArray = [NSMutableArray array];
//    for (Movielist *movie in array) {
//        if ([movie.userName isEqualToString:userName]) {
//            
//            [self.rowArray addObject:movie];
//            
//        }
//    }
//    
    NSLog(@"........%@",self.rowArray);
    return self.rowArray.count;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdenfier =@"cell";
    MovieDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenfier];
    
    Movielist *movie = [[Movielist alloc]init];
    movie = [self.rowArray objectAtIndex:indexPath.row];
    NSLog(@"=====1111%@",movie);
    cell.titleName.text = movie.movieName;
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MovieDetalViewController *movieDVC = [[MovieDetalViewController alloc]init];
    
    Movielist *movie = [[Movielist alloc]init];
    movie = [self.rowArray objectAtIndex:indexPath.row];
    NSLog(@"++++++++%@",movie.movieId);
    movieDVC.amovie = movie;
    
    [self.navigationController pushViewController:movieDVC animated:YES];
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
